﻿using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
namespace INTEX.DataBase.Tools
{
    public partial class INTEXDBC
    {
        public void SaveICC_PRNDEF(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet Result = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            Result = QueryICC_PRNDEF(dwData);
            if (Result.Tables.Count > 0)
            {
                tbLocal = Result.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }

            MapICC_PRNDEF(ref dwLocal, dwData);

            if (!flgExist)
            {
                dwLocal["ROWNID"] = GetSeq();
                InsertICC_PRNDEF(dwLocal, ITXDBVERSION);
            }
            UpdateICC_PRNDEF(dwLocal);
        }
        public void InsertICC_PRNDEF(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "50.24":
                    or1.CommandText = "INSERT INTO ICC_PRNDEF(MANDANT, ROWNID, COMPANY, USERID, KUNDNR, PRNAME, PRPROG, PRCOND, PRDES, PRVER, PRLX, PRLY, PRRX, PRRY, PRLTHICK, PRCTYPE, PRCTYPDES, PRFONT, PRFONTSIZE, PRCONTENT, PRCONTDES, PRAENDAT)"
                    + " VALUES (:MANDANT,:ROWNID,:COMPANY,:USERID,:KUNDNR,:PRNAME,:PRPROG,:PRCOND,:PRDES,:PRVER,:PRLX,:PRLY,:PRRX,:PRRY,:PRLTHICK,:PRCTYPE,:PRCTYPDES,:PRFONT,:PRFONTSIZE,:PRCONTENT,:PRCONTDES,:PRAENDAT)";
                    break;
                default:
                    break;
            }
            or1.Parameters.Add("MANDANT", OracleType.NVarChar).Value = dwData["MANDANT"].ToString();
            or1.Parameters.Add("ROWNID", OracleType.NVarChar).Value = dwData["ROWNID"].ToString();
            or1.Parameters.Add("COMPANY", OracleType.NVarChar).Value = dwData["COMPANY"].ToString();
            or1.Parameters.Add("USERID", OracleType.NVarChar).Value = dwData["USERID"].ToString();
            or1.Parameters.Add("KUNDNR", OracleType.NVarChar).Value = dwData["KUNDNR"].ToString();
            or1.Parameters.Add("PRNAME", OracleType.NVarChar).Value = dwData["PRNAME"].ToString();
            or1.Parameters.Add("PRPROG", OracleType.NVarChar).Value = dwData["PRPROG"].ToString();
            or1.Parameters.Add("PRCOND", OracleType.NVarChar).Value = dwData["PRCOND"].ToString();
            or1.Parameters.Add("PRDES", OracleType.NVarChar).Value = dwData["PRDES"].ToString();
            or1.Parameters.Add("PRVER", OracleType.NVarChar).Value = dwData["PRVER"].ToString();
            or1.Parameters.Add("PRLX", OracleType.NVarChar).Value = dwData["PRLX"].ToString();
            or1.Parameters.Add("PRLY", OracleType.NVarChar).Value = dwData["PRLY"].ToString();
            or1.Parameters.Add("PRRX", OracleType.NVarChar).Value = dwData["PRRX"].ToString();
            or1.Parameters.Add("PRRY", OracleType.NVarChar).Value = dwData["PRRY"].ToString();
            or1.Parameters.Add("PRLTHICK", OracleType.NVarChar).Value = dwData["PRLTHICK"].ToString();
            or1.Parameters.Add("PRCTYPE", OracleType.NVarChar).Value = dwData["PRCTYPE"].ToString();
            or1.Parameters.Add("PRCTYPDES", OracleType.NVarChar).Value = dwData["PRCTYPDES"].ToString();
            or1.Parameters.Add("PRFONT", OracleType.NVarChar).Value = dwData["PRFONT"].ToString();
            or1.Parameters.Add("PRFONTSIZE", OracleType.NVarChar).Value = dwData["PRFONTSIZE"].ToString();
            or1.Parameters.Add("PRCONTENT", OracleType.NVarChar).Value = dwData["PRCONTENT"].ToString();
            or1.Parameters.Add("PRCONTDES", OracleType.NVarChar).Value = dwData["PRCONTDES"].ToString();
            or1.Parameters.Add("PRAENDAT", OracleType.NVarChar).Value = dwData["PRAENDAT"].ToString();
            Connect2Proxy(or1);
        }
        public void DeleteICC_PRNDEF(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM ICC_PRNDEF  WHERE MANDANT=:MANDANT AND ROWNID=:ROWNID";
                    or1.Parameters.Add("MANDANT", OracleType.NVarChar).Value = dwData["MANDANT"];
                    or1.Parameters.Add("ROWNID", OracleType.NVarChar).Value = dwData["ROWNID"];
                    break;
                case 2:
                    or1.CommandText = "DELETE FROM ICC_PRNDEF  WHERE MANDANT=:MANDANT AND KUNDNR=:KUNDNR";
                    or1.Parameters.Add("MANDANT", OracleType.NVarChar).Value = dwData["MANDANT"];
                    or1.Parameters.Add("KUNDNR", OracleType.NVarChar).Value = dwData["KUNDNR"];
                    break;
                default:
                    break;
            }

            Connect2Proxy(or1);
        }
        public DataSet QueryICC_PRNDEF(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "SELECT * FROM ICC_PRNDEF WHERE MANDANT=:MANDANT  AND ROWNID=:ROWNID"; ;
                    or1.Parameters.Add("MANDANT", OracleType.NVarChar).Value = dwData["MANDANT"].ToString();
                    or1.Parameters.Add("ROWNID", OracleType.NVarChar).Value = dwData["ROWNID"].ToString();
                    break;
                case 2:
                    or1.CommandText = "SELECT * FROM ICC_PRNDEF "
                    + " WHERE MANDANT=:MANDANT AND KUNDNR=:KUNDNR AND TRIM(PRNAME)=:PRNAME"
                    + " ORDER BY TO_NUMBER(PRLY),TO_NUMBER(PRLX)"; ;
                    or1.Parameters.Add("MANDANT", OracleType.NVarChar).Value = dwData["MANDANT"].ToString();
                    or1.Parameters.Add("KUNDNR", OracleType.NVarChar).Value = dwData["KUNDNR"].ToString();
                    or1.Parameters.Add("PRNAME", OracleType.NVarChar).Value = dwData["PRNAME"].ToString().Trim();
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "ICC_PRNDEF";
            Return = Result;
            return Return;
        }
        public void UpdateICC_PRNDEF(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();

            #region====Command====
            or1.CommandText = "UPDATE ICC_PRNDEF SET "
                + "MANDANT=:MANDANT,"
                + "ROWNID=:ROWNID,"
                + "COMPANY=:COMPANY,"
                + "USERID=:USERID,"
                + "KUNDNR=:KUNDNR,"
                + "PRNAME=:PRNAME,"
                + "PRPROG=:PRPROG,"
                + "PRCOND=:PRCOND,"
                + "PRDES=:PRDES,"
                + "PRVER=:PRVER,"
                + "PRLX=:PRLX,"
                + "PRLY=:PRLY,"
                + "PRRX=:PRRX,"
                + "PRRY=:PRRY,"
                + "PRLTHICK=:PRLTHICK,"
                + "PRCTYPE=:PRCTYPE,"
                + "PRCTYPDES=:PRCTYPDES,"
                + "PRFONT=:PRFONT,"
                + "PRFONTSIZE=:PRFONTSIZE,"
                + "PRCONTENT=:PRCONTENT,"
                + "PRCONTDES=:PRCONTDES,"
                + "PRAENDAT=:PRAENDAT "
                + " WHERE  "
                + "  MANDANT=:MANDANT AND ROWNID=:ROWNID";
            #endregion

            #region====Parameters====
            or1.Parameters.Add("MANDANT", OracleType.NVarChar).Value = dwData["MANDANT"].ToString();
            or1.Parameters.Add("ROWNID", OracleType.NVarChar).Value = dwData["ROWNID"].ToString();
            or1.Parameters.Add("COMPANY", OracleType.NVarChar).Value = dwData["COMPANY"].ToString();
            or1.Parameters.Add("USERID", OracleType.NVarChar).Value = dwData["USERID"].ToString();
            or1.Parameters.Add("KUNDNR", OracleType.NVarChar).Value = dwData["KUNDNR"].ToString();
            or1.Parameters.Add("PRNAME", OracleType.NVarChar).Value = dwData["PRNAME"].ToString();
            or1.Parameters.Add("PRPROG", OracleType.NVarChar).Value = dwData["PRPROG"].ToString();
            or1.Parameters.Add("PRCOND", OracleType.NVarChar).Value = dwData["PRCOND"].ToString();
            or1.Parameters.Add("PRDES", OracleType.NVarChar).Value = dwData["PRDES"].ToString();
            or1.Parameters.Add("PRVER", OracleType.NVarChar).Value = dwData["PRVER"].ToString();
            or1.Parameters.Add("PRLX", OracleType.NVarChar).Value = dwData["PRLX"].ToString();
            or1.Parameters.Add("PRLY", OracleType.NVarChar).Value = dwData["PRLY"].ToString();
            or1.Parameters.Add("PRRX", OracleType.NVarChar).Value = dwData["PRRX"].ToString();
            or1.Parameters.Add("PRRY", OracleType.NVarChar).Value = dwData["PRRY"].ToString();
            or1.Parameters.Add("PRLTHICK", OracleType.NVarChar).Value = dwData["PRLTHICK"].ToString();
            or1.Parameters.Add("PRCTYPE", OracleType.NVarChar).Value = dwData["PRCTYPE"].ToString();
            or1.Parameters.Add("PRCTYPDES", OracleType.NVarChar).Value = dwData["PRCTYPDES"].ToString();
            or1.Parameters.Add("PRFONT", OracleType.NVarChar).Value = dwData["PRFONT"].ToString();
            or1.Parameters.Add("PRFONTSIZE", OracleType.NVarChar).Value = dwData["PRFONTSIZE"].ToString();
            or1.Parameters.Add("PRCONTENT", OracleType.NVarChar).Value = dwData["PRCONTENT"].ToString();
            or1.Parameters.Add("PRCONTDES", OracleType.NVarChar).Value = dwData["PRCONTDES"].ToString();
            or1.Parameters.Add("PRAENDAT", OracleType.NVarChar).Value = dwData["PRAENDAT"].ToString();
            #endregion

            Connect2Proxy(or1);
        }
    }
}
